package com.bensonbasement.snorflux.server.world;

import java.util.LinkedList;
import java.util.List;

import com.bensonbasement.snorflux.memory.SmallEntityInfo;
import com.bensonbasement.snorflux.server.world.prototypes.EntityPrototype;
import com.bensonbasement.snorflux.server.world.prototypes.SmallEntityPrototype;

public class SmallEntity extends Entity {

	private ISmallEntityHolder location = null;
	
	public SmallEntity(World world, SmallEntityPrototype prototype) {
		super(world, prototype);
		// TODO Auto-generated constructor stub
	}
	
	@Override
	protected SmallEntityPrototype getPrototype() {
		return (SmallEntityPrototype) super.getPrototype();
	}
	
	public void setLocation(ISmallEntityHolder newLocation) {
		this.setLocationHelper(newLocation);
	}

	public ISmallEntityHolder getLocation() {
		return location;
	}
	
	@Override
	public SmallEntityInfo render(IViewer viewer) {
		// TODO: Update this when the Jython attribute stuff is created.
		if (viewer.canSeeInLocation(this.getLocation())) {
			SmallEntityInfo retVal = new SmallEntityInfo(this.getWorldElementID(),this.getGlyph(),this.getName(),this.getLocation().getWorldElementID());
			return retVal;
		}
		else {
			return null;
		}
	}

	@Override
	protected void addSelfTo(ILocation location) {
		ISmallEntityHolder loc = (ISmallEntityHolder) location;
		loc.addSmallEntity(this);
	}

	@Override
	protected void removeSelfFrom(ILocation location) {
		ISmallEntityHolder loc = (ISmallEntityHolder) location;
		loc.removeSmallEntity(this);
	}

	@Override
	protected void actuallySetLocation(ILocation location) {
		ISmallEntityHolder loc = (ISmallEntityHolder) location;
		this.location = loc;
	}
	
	public List<WorldElement> getAllWorldElements() {
		List<WorldElement> retVal = new LinkedList<WorldElement>();
		retVal.add(this);
		return retVal;
	}

}
